package view;

import data.Data_Book;
import data.Data_Canvas;
import tree.LeafMsg;
import tree.Root;
import tree.LeafKind;
import tree.Leaf;

class Leaf_AutoPlay extends Leaf {
    var lasttime : Float;
    var interval : Float;

    var page : Int;
    
    public function new() {
        super();
    }

    public override function OnEnter(last:LeafKind) {
        super.OnEnter(last);

        page = data_book.curpage;
        data_canvas.isAutoPlay = true;
        lasttime = Root.instance.time;
        interval = 0.2;
    }

    public override function OnUpdate(msg:LeafMsg) {
        super.OnUpdate(msg);
        if(Root.instance.time - lasttime > interval){
            //切换图片
            lasttime += interval;
            data_book.NextPage();
        }
    }

    public override function OnExit(next:LeafKind) {
        super.OnExit(next);
        data_book.ChangeCurPage(page);
        data_canvas.isAutoPlay = false;
    }
}